<template>
	<view class="goods"
	@tap="goodsInfo.itemendprice?
	goodDetail(
	goodsInfo.itemid
	):
	goodDetail(
	goodsInfo.num_iid
	)">
		<image :src="goodsInfo.pict_url || goodsInfo.itempic" class="good-img"></image>
		<view class="good-name">{{goodsInfo.short_title || goodsInfo.itemshorttitle}}</view>
		<view class="good-shop">
			<image src="../../static/common/taobao.png" class="good-source-icon"></image>
			<view class="good-shopname">{{goodsInfo.shop_title || goodsInfo.shopname}}</view>
			<view class="good-quan">￥{{goodsInfo.coupon || goodsInfo.couponmoney}}券</view>
		</view>
		<view class="good-price">
			<view class="after-quan">券后价￥<text class="quan-detail" ref="quan-detail">
			{{  goodsInfo.itemendprice?goodsInfo.itemendprice: calculation(goodsInfo.zk_final_price,goodsInfo.coupon)}}
			</text></view>
			<!-- <view class="quan-detail">12</view> -->
			<view class="zhuang">
				<view class="coin">￥</view>
				<view class="zhuang-detail">
				{{ goodsInfo.itemendprice? calculationRateHot(goodsInfo.itemendprice,goodsInfo.tkrates):calculationRate(goodsInfo.zk_final_price,goodsInfo.coupon,goodsInfo.commission_rate)}}
				</view>
			</view>
		</view>
		<view class="yuanjia_xiaoliang">
			<view class="yuanjia">原价:{{goodsInfo.itemprice || goodsInfo.zk_final_price}}</view>
			<view class="xiaoliang">销量: {{calculationXL(goodsInfo.volume)  || calculationXL(goodsInfo.itemsale) }}w</view>
		</view>
	</view>
</template>

<script>
	export default{
		name:"good",
		data(){
			return{
				yongjin:"",
			}
		},
		props:{
			goodsInfo:{
				type:Object,
			}
		},
		
		methods:{
			calculationXL(num){
				num = num /10000;
				const newNum = Math.floor(num * 100) / 100;
				return newNum;
			},
			goodDetail(id){
				var _this = this;
				
				// const coupon = {
				// 	coupon:num,
				// 	startTime:startTime,
				// 	endTime:endTime
				// }
				//console.log(coupon)
				uni.setStorage({
				    key: 'yongjin',
				    data: this.yongjin,
						success() {
							_this.$emit('goodsDetail',id);
						}
				});
				//商品详情
				// uni.setStorage({
				//     key: 'product_id',
				//     data: id,
				//     success: function () {
				// 			_this.$emit('goodsDetail',coupon);
				//     }
				// });
				
			},
			calculationRateHot(itemendprice,tkrates){
				//推荐商品计算佣金
				//佣金=券后价*佣金比例/1000*0.8
				const num = (itemendprice * tkrates)/1000*0.8;
				if(Math.floor(num) == num){
					this.yongjin = num;
					return num
				}else{
					this.yongjin = num.toFixed(2);
					return num.toFixed(2)
				}
				
			},
			calculation(zk_final_price,coupon){
				//计算券后价分类
				const num = zk_final_price - coupon;
				if(Math.floor(num) == num){
					return num
				}else{
					return num.toFixed(2);
				}
				
			},
			calculationRate(zk_final_price,coupon,commission_rate){
				//计算佣金分类
				//佣金 = 券后价 * 佣金比例 * 0.8
				//佣金比例 = 佣金比例/100/100
				//1.要先计算券后价
				const endPrice = zk_final_price - coupon;
				//2.计算佣金
				const num = endPrice * (commission_rate / 10000) * 0.8;
				if(Math.floor(num) == num){
					this.yongjin = num;
					return num
				}else{
					this.yongjin = num.toFixed(2);
					return num.toFixed(2)
				}
			}
		}
	}
</script>

<style>
	@import url("good.css");
	.yuanjia_xiaoliang{
		width: calc(100% - 16upx);
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		padding: 8upx 15upx;
	}
	.yuanjia{
		font-size: 11px;
		color: #CCCCCC;
		text-decoration: line-through;
	}
	.xiaoliang{
		font-size: 11px;
		color: #999;
	}
</style>
